import useUserStore from "@/store/user";
import projectSetting from "@/settings/project";

export const btnPermissionDirective = {
  mounted(el, binding) {
    if (!projectSetting.openBtnPermission) {
      return;
    }
    let permissions = useUserStore.autnInfo.permissions;
    if (binding.value) {
      if (!permissions.includes(binding.value)) {
        el.remove();
      }
    }
  }
};

export const judgeBtnPermission = (permission: string | number) => {
  if (!projectSetting.openBtnPermission) {
    return true;
  }
  let permissions = useUserStore.autnInfo.permissions;
  if (!permissions.includes(permission)) {
    return false;
  } else {
    return true;
  }
};
